//
//  UIView+Animation.swift
//  ShowDance
//
//  Created by 苏泊尔漫也要按时吃饭 on 2022/12/22.
//

import Foundation

extension UIView {
    
    
    func zoomIn(duration: TimeInterval = 0.3) {
        
        self.layer.position = CGPoint(x: self.centerX, y: self.centerY)
        self.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
        self.alpha = 0;
        self.transform = CGAffineTransformMakeScale(0.01, 0.01)
        UIView.animate(withDuration: 0.3, delay: 0.0, options: [.curveLinear], animations: { () -> Void in
            self.alpha = 1;
            self.transform = CGAffineTransformMakeScale(1.05, 1.05);
            
        }) { (animationCompleted: Bool) -> Void in
            
            UIView.animate(withDuration: 0.1) {
                self.transform = CGAffineTransformMakeScale(1, 1);
            }completion: { finish in
                self.transform = CGAffineTransformIdentity;
            }
        }
    }
    
    func zoomOut(duration: TimeInterval = 2) {
        self.layer.position = CGPoint(x: self.centerX, y: self.centerY)
        self.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
        self.transform = CGAffineTransformMakeScale(1 , 1);
        
        UIView.animate(withDuration: 0.3, delay: 0.0, options: [.curveLinear], animations: { () -> Void in
            self.alpha = 0
            self.transform = CGAffineTransformMakeScale(0.01 , 0.01);
        }) { (animationCompleted: Bool) -> Void in
            self.transform = CGAffineTransformIdentity;
            self.alpha = 0;
        }
    }
}
